package com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.QualityAssuranceInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.RootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.SearchQualityAssuranceInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.SearchRootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.service.IDentalImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 质量管理控制器
 *
 * @author fengshuonan
 * @Date 2019-09-01 15:34:05
 */
@Controller
@RequestMapping("/rootPeriodontal")
public class RootpPeriodontalImageController extends BaseController {
    @Autowired
    IDentalImageService service;

    @Autowired
    private SqlMapper sqlMapper;

    /**
     * 牙周影像列表
     */
    @RequestMapping(value = {"/list/{reservationsId}", "/list"})
    @ResponseBody
    public Object list(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId, HttpServletRequest request) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = service.selectPageListByPeriodontal(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.selectPageListByPeriodontal(page, info);
            }
            page.setTotal(service.getQueryPagePeriodontalCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    //获取牙周 图片
    @RequestMapping(value = "/getImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getImgcancel(String num,String iconType,String classification) throws Exception {
        String sql = "select * from root_periodontal_imgs_info where num='" + num + "' and imgtpye='"+iconType+"' and classification='"+classification+"' ";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        return infoList;
    }

}
